"""
 教学科班主任时长excel切分功能
"""
# -*- coding: utf-8 -*-
import openpyxl
from openpyxl import Workbook

if __name__ == '__main__':
    workbook = openpyxl.load_workbook('D:/projects/jxk/23年春季学期开放学院教学安排表.xlsx')
    # 生成新的excel文档
    new_workbook = Workbook()
    new_sheet = new_workbook.active

    sheet = workbook.active
    row = []
    # 迭代工作表中的每一行
    for row in sheet.iter_rows():
        # 列表推导式获取当前行中的所有单元格值
        row_data = [cell.value for cell in row]
        if row_data[16] is not None:
            # 判断逗号
            if ',' in row_data[16]:
                # 根据逗号切割
                time = row_data[16].split(',')
                for item in time:
                    row_data[16] = item
                    new_sheet.append(row_data)
            else:
                new_sheet.append(row_data)
        else:
            new_sheet.append(row_data)
    # 本地保存test.xlsx
    new_workbook.save("D:/projects/jxk/2.xlsx")
